package com.jzxy.PingFen.service.ipml;

import com.jzxy.PingFen.mapper.AllMapper;
import com.jzxy.PingFen.pojo.LoginUser;
import com.jzxy.PingFen.pojo.User;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * ClassName:UserDetailsServiceImpl
 * Package:com.jzxy.PingFen.service.ipml
 * Description:
 *
 * @Author: dlh
 * @Creat:2025/1/14-16:02
 */
@Slf4j
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Autowired
    private AllMapper allMapper;
    @Override
    public UserDetails loadUserByUsername(String username){
        User user = allMapper.selectUser(username);
        if (user==null){
            log.error("用户不存在");
            throw new RuntimeException("用户不存在");
        }
        //根据用户查询权限信息 添加到LoginUser中
//        List<String> list = allMapper.selectAuthentication(user.getUserId());
//        List<String> list = new ArrayList<>(Arrays.asList("test"));
        Integer roleId = allMapper.selectAuthentication1(user.getUserId());
        List<Integer> menuIdList = allMapper.selectAuthentication2(roleId);
        List<String> list =allMapper.selectAuthentication3(menuIdList);


        return new LoginUser(user, list);
    }
}
